package com.test.dubbo;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

public class DubboDecoder extends ReplayingDecoder<Void>
{
		@Override
		protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
			//需要将得到二进制字节码-> MessageProtocol 数据包(对象)
			int length = in.readInt();
			byte[] content = new byte[length];
			in.readBytes(content);
			//封装成 MessageProtocol 对象，放入 out， 传递下一个handler业务处理
			DubboProtocol dubboProtocol = new DubboProtocol ();
			dubboProtocol.setLen(length);
			dubboProtocol.setContent(content);
			out.add(dubboProtocol);
		}
}
